package com.ruoyi.system.service.news.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.ruoyi.system.domain.news.NewsInfoSearch;
import com.ruoyi.system.domain.news.query.NewsInfoSearchQuery;
import com.ruoyi.system.domain.news.vo.NewsInfoSearchVo;
import com.ruoyi.system.domain.news.vo.NewsInfoSearchVo;
import com.ruoyi.system.mapper.news.NewsInfoSearchMapper;
import com.ruoyi.system.service.news.NewsInfoSearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class NewsInfoSearchServiceImpl extends ServiceImpl<NewsInfoSearchMapper, NewsInfoSearch>
        implements NewsInfoSearchService {

    @Override
//    @DataScope(deptAlias = "t",userAlias = "t")
    public List<NewsInfoSearchVo> getNewsInfoSearchList(NewsInfoSearchQuery newsInfoSearchQuery) {
        if (newsInfoSearchQuery.getIfPage()) {
            PageHelper.startPage(newsInfoSearchQuery.getPageNum(), newsInfoSearchQuery.getPageSize());
        }
        List<NewsInfoSearchVo> newsInfoSearchVoList = baseMapper.getNewsInfoSearchList(newsInfoSearchQuery);
        if (!newsInfoSearchVoList.isEmpty() && newsInfoSearchQuery.getId() == null) {
            for (NewsInfoSearchVo newsInfoSearchVo:newsInfoSearchVoList) {
                newsInfoSearchVo.setContent(null);
            }
        }
        return newsInfoSearchVoList;
    }
}
